package StudyCode.summary.mydatetime;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Month;

import static java.time.temporal.ChronoUnit.*;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class Elapsed {
	public static void main(String[] args) {
		LocalDate ld1 = LocalDate.of(2019, Month.JANUARY, 7);
		LocalDate ld2 = LocalDate.of(2019, Month.MAY, 18);
		long days = DAYS.between(ld1, ld2);
		LocalTime lt1 = LocalTime.of(7, 0);
		LocalTime lt2 = LocalTime.of(9, 30);
		long hours = HOURS.between(lt1, lt2);
		long minutes = MINUTES.between(lt1, lt2);

		System.out.println("Using between (days): " + days);
		System.out.println("Using between (hours): " + hours);
		System.out.println("Using between (minutes): " + minutes);

		// 使用 until 方法
		long days2 = ld1.until(ld2, DAYS);
		long hours2 = lt1.until(lt2, HOURS);
		long minutes2 = lt1.until(lt2, MINUTES);

		System.out.println("Using until (days): " + days2);
		System.out.println("Using until (hours): " + hours2);
		System.out.println("Using until (minutes): " + minutes2);
	}
}
